$(function() {
	$(".close").click(function() {
		$("#ter_details").css('display', 'none');
	});
});

function getCounty(dom) {
	var index = $(dom).children('option:selected').val();
	alert(index);

	if (0 != index) {
		$.ajax({
			url : "<@spring.url '/common/cities'/>",
			type : 'post',
			data : {
				"id" : index
			},
			success : function(data) {
				$('#citySelect').html(data);
			}
		});
	} else {
		$('#citySelect').html('<option value="0">--请选择--</option>');
	}
}

function searchChange() {
	var index = $('#select_time').children('option:selected').val();
	if (index == 2) {
		$('#select_month').removeAttr("disabled");
		flag = 2;
	} else {
		$("#select_month").attr("disabled", "disabled");
		flag = 1;
	}
}

function searchAgentByKeyword() {
	var key = $("#search_keys").val();
	$.ajax({
		url : "<@spring.url '/transactionrep/dimsearch'/>",
		type : 'post',
		data : {
			"key" : key
		},
		success : function(data) {
			$('#searchContent').css("display", "block");
			$('#searchContent').html(data);
		}
	});
}

function saveRawVal() {
	var rawKey = $("#search_keys").val();
}

function mouseHover(li) {
	$(li).css("background", "#ccc");
}

function mouseOut(li) {
	$(li).css("background", "#FAFAFA");
}

function getKey(li) {
	$('#search_keys').val($(li).text().trim());
	$('#searchContent').css("display", "none");
}
function hide_head() {
	$('#searchContent').hide();
}

function search() {
	var time = getTime(flag);// 查询时间
	var cityid = $('#citySelect').val();// 城市ID
	var operatorid = $('#operatorid').val();// 运营人员ID
	var agentname = $('#search_keys').val();// 合伙人ID
	// alert("时间:" + time + ",时间查询类型:" + flag + ",城市ID:" + cityid + ",运营人员ID:" +
	// operatorid + ",合作伙伴ID:" + agentname);

	$.post("<@spring.url '/transactionrep/search'/>", {
		"time" : time,
		"cityid" : cityid,
		"operatorid" : operatorid,
		"agentname" : agentname,
		"flag" : flag
	}, function(data) {
		$("#data_list").html(data);
	});

	$.post("<@spring.url '/transactionrep/totalTrans'/>", {
		"time" : time,
		"cityid" : cityid,
		"operatorid" : operatorid,
		"agentname" : agentname,
		"flag" : flag
	}, function(data) {
		$("#totalTrans_result").html(data);
	});

}
function details(agent_id) {
	var time = getTime(flag);// 查询时间
	var month = $('#select_month').val();
	var cityid = $('#citySelect').val();
	var operatorid = $('#operatorid').val();
	var agentname = $('#search_keys').val();
	// alert("time: " + time + "agentid: " + agent_id + "operatorid: " +
	// operatorid + "cityid: " + cityid);

	$.post("<@spring.url '/transactionrep/getDetails'/>", {
		"time" : time,
		"cityid" : cityid,
		"operatorid" : operatorid,
		"agentid" : agent_id,
		"flag" : flag
	}, function(data) {
		$('#data_details_list').html(data);
		$('#ter_details').show();
		console.info(data);
	});

}

// 导出
function exportTotal() {
	var time = getTime(flag);// 查询时间
	var cityid = $('#citySelect').val();
	var operatorid = $('#operatorid').val();
	var agentname = $('#search_keys').val();
	// alert("time: " + time + "agentname: " + agentname + "operatorid: " +
	// operatorid + "cityid: " + cityid);

	var path = flag + "/" + time + "/" + cityid + "/" + operatorid;
	if ("" == agentname || agentname == null) {
		window.location.href = "<@spring.url " / transactionrep / exportTotal / " />" + path;
	} else {
		window.location.href = "<@spring.url " / transactionrep / exportTotalWithName / " />" + agentname + "/" + path;
	}

}

// 导出明细
function exportDetails() {
	var agentname = $('#agentRowId').find('td:eq(0)').text().trim();
	var time = getTime(flag);// 查询时间
	var cityid = $('#citySelect').val();
	var operatorid = $('#operatorid').val();
	console.info(agentname);

	var path = agentname + "/" + flag + "/" + time + "/" + +cityid + "/" + operatorid;
	window.location.href = "<@spring.url " / transactionrep / exportDetails / " />" + path;

}
// 获取查询时间
function getTime(flag) {
	var time = 0;
	if (1 == flag) {// 按天查询
		if (0 == $('#select_time').val()) {
			time = 0;
		} else if (1 == $('#select_time').val()) {
			time = 7;
		}
	} else if (2 == flag) {// 按月查询
		time = $('#select_month').val();
	}
	return time;
}